package Lee_code;

import java.util.*;

public class Lee_841 {
    int room_num;
    public boolean canVisitAllRooms(List<List<Integer>> rooms) {

        room_num = rooms.size();
        //已经访问的哈希房间集合
        HashSet<Integer> visited = new HashSet<>();
        //搞一个队列
        Queue<Integer> queue= new LinkedList<>();

        queue.offer(0);
        while(!queue.isEmpty())
        {
            int status = queue.poll();
            List<Integer> temp = new ArrayList<>(rooms.get(status));
            for(Integer in: temp)
            {
                if(!visited.contains(in))
                {
                    queue.offer(in);
                }
            }
            visited.add(status);
        }
        return (visited.size()==room_num);
    }
    public static void main(String[] args) {

    }
}
